define(['jquery', 'vue', 'common', 'ELEMENT'], function($, Vue, common, ELEMENT) {
    const Controller = {
        index: function () {
            const {createApp, ref, onMounted,watch} = Vue
            const app = createApp({
                setup(){
                    const pk = ref('id')
                    const list = ref({
                        total:0,
                        rows:[],
                        page:1,
                        limit:10,
                        seachObj:[]
                    })
                    const piviewType = ref([
                        'png',
                        'jpg',
                        'jpeg',
                        'gif',
                        'bmp',
                        'webp',
                        'svg',
                    ])
                    const delList = ref([])
                    const table = ref(null)
                    const seach = common.getQueryParamsAsObject()
                    console.log(seach,'ssssssssssssssssssssssssss')
                    const getIndexData = ()=>{
                        common.loadingIndexData(list.value).then(res=>{
                            if(res.code==1){
                                list.value.rows = res.data.rows
                                list.value.total = res.data.total
                            }
                        })
                    }
                    onMounted(()=>{
                        getIndexData()
                    })
                    const changePage = (page)=>{
                        list.value.page = page
                        console.log(table.value.getSelectionRows())
                        let selected = table.value.getSelectionRows()
                        selected.forEach(item=>{
                            delList.value.push(item[pk.value])
                        })
                        getIndexData()
                    }
                    const changeSize = (size)=>{
                        list.value.limit = size
                        getIndexData()
                    }
                    window.refresh = ()=>{
                        getIndexData()
                    }
                    common.refresh = getIndexData
                    watch(delList.value,(newValue)=>{
                        console.log(newValue)
                    })
                    const selectionChange = (row)=>{
                        // console.log(row)
                        let newlist =[];
                        row.forEach(item=>{
                            newlist.push(item[pk.value])
                        })
                        delList.value = newlist
                    }
                    const delAll = ()=>{
                        console.log("删除全部")
                        if(delList.value.length>0){
                            let str = delList.value.join(',')
                            common.del(str,pk.value)
                        }else{
                            common.message('请选择要删除的数据')
                        }
                    }
                    const selectFile = (row)=>{
                        console.log(row)
                        if(seach?.multiple==1){

                        }else{
                            let url = row.url;
                            if(parent?.window?.callback){
                                parent.window.callback(url)
                            }
                            var index = parent.layer.getFrameIndex(window.name)
                            parent.layer.close(index);
                        }
                    }
                    return {
                        list,
                        getTime:common.getTime,
                        piviewType,
                        changePage,
                        changeSize,
                        common:common,
                        delList,
                        table,
                        selectionChange,
                        delAll,
                        seach,
                        selectFile
                    }
                }
            })
            common.load(app,false)
            app.mount('#app')
        },
        add:()=>{
            const {createApp,  ref, onMounted,watch} = Vue
            const app = createApp({
                setup(){
                    const fileList = ref("")
                    watch(()=>fileList.value,(newValue)=>{
                        parent.window.refresh()
                    })
                    return {
                        fileList
                    }
                }
            })
            common.load(app)
            app.mount('#app')
        }
    }
    return Controller
})